package com.chen.web;

import com.chen.web.dao.UserRepository;
import org.apache.log4j.Logger;
import org.bouncycastle.ocsp.Req;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.lang.ref.ReferenceQueue;


/**
 * @decription
 * @atuhor:陈红卫
 * @create : 2017-06-16-9:39
 */
@RestController
public class HelloController {

    private final Logger logger = Logger.getLogger(getClass());


    @Autowired
    private UserRepository userRepository;


    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    public String index(){

        ServiceInstance instanceClient =discoveryClient.getLocalServiceInstance();

        logger.info("/hello, host:" + instanceClient.getHost() + ", service_id:" + instanceClient.getServiceId());
        return "Hello word";
    }


    @RequestMapping(value = "/hello1",method = RequestMethod.GET)
    public String hello(@RequestParam String name){
        return "Hello " +name;
    }

    @RequestMapping(value ="/hello2",method = RequestMethod.GET)
    public User hello(@RequestHeader  String name, @RequestHeader Integer age)
    {
        return new User(Long.valueOf(1) ,name,age,"江西省，上饶市 广丰");
    }


    @RequestMapping(value = "/hello3",method = RequestMethod.POST)
    public String hello(@RequestBody User user)
    {
        return "hello" +user.getName()+","+user.getAge();
    }

















    @RequestMapping(value="getUserById",method =RequestMethod.GET)
    public User getUserById(Long id){
        User user = new User();
        user=userRepository.findOne(id.longValue());
        return user;
    }
}
